package com.sh.data.engine.application.model.mapper.integration;

import com.sh.data.engine.application.model.request.integration.*;
import com.sh.data.engine.common.enumDefinition.DSType;
import com.sh.data.engine.domain.integration.datasource.model.param.*;
import org.mapstruct.Mapper;

@Mapper(componentModel = "spring")
public interface DataSourceConnParamMapper {
    DataSourceConnectParam requestToParam(DataSourceGeneralConnectionRequest request);

    DataSourceHiveConnectParam requestToHiveParam(DataSourceGeneralConnectionRequest request);

    DataSourceMongoConnectParam requestToMongoParam(DataSourceGeneralConnectionRequest request);

    DataSourceHDFSConnectParam requestToHDFSParam(DataSourceGeneralConnectionRequest request);

    DataSourceIoTDBConnectParam requestToIoTDBParam(DataSourceGeneralConnectionRequest request);

    DataSourceInfluxDBConnectParam requestToInfluxDBParam(DataSourceGeneralConnectionRequest request);

    default DataSourceConnectParam map(DataSourceGeneralConnectionRequest request) {
        if (request == null) {
            return requestToParam(request);
        }

        if (DSType.isRdbms(request.getDsType().name())) {
            return requestToParam(request);
        } else if (request.getDsType() == DSType.Hive) {
            return requestToHiveParam((request));
        } else if (request.getDsType() == DSType.Mongodb) {
            return requestToMongoParam(request);
        } else if (request.getDsType() == DSType.HDFS) {
            return requestToHDFSParam(request);
        } else if (request.getDsType() == DSType.IoTDB) {
            return requestToIoTDBParam(request);
        } else if (request.getDsType() == DSType.InfluxDB) {
            return requestToInfluxDBParam(request);
        } else {
            return requestToParam(request);
        }

    }
}
